<!--  -->
<template>
  <div id="container">
     <HeaderQ></HeaderQ>
    <Navigation ></Navigation>
    <div id="wrapList01" class="clearfix">
    <div class="wraplist01 clearfix mt60 myQuestion newQuestion" v-cloak>
        <div class="fl list-left">
            <div class="left-top">
                <h2 class="h2-top ellipsis mb20" v-bind:title="qinfo.Title">{{qinfo.Title}}</h2>
                <div class="ques-con" v-html="htmlEncode(qinfo.Content)"></div>
                <p class="date tr">
                    <span class=""><img v-bind:src="qinfo.HeadImg" style="width: 25px"> {{qinfo.RealName}}</span>
                    <span class="">{{qinfo.CreateTime|datetime}}</span>
                </p>
            </div>
            <div class="left-bottom">
                <h2 class="h2-top mb10 mt40">回答数：{{qinfo.AnswerNum}}</h2>
                <a v-on:click="focuseEditor()" class="btn ib fr btn-ques">我要回答</a>
                
                <div class="replay-con">
                 
                        <div  v-if="bestanswer">
                            <h2 class="best mb20 mt20">最佳答案：</h2>
                            <div class="replay01">
                                <div class="replay-top date clearfix">
                                    <p class="fl clearfix">
                                        <span>
                                            <img v-bind:src="bestanswer.HeadImg" style="width: 25px"> {{bestanswer.RealName}}
                                        </span>
                                        <span>{{bestanswer.CreateTime}}</span>
                                    </p>
                                </div>
                                <div class="replay-bottom mb20 replay-best" style="max-width: 100%" v-html="bestanswer.Content"></div>
                            </div>
                        </div>
                    
                    <h2 class="other-h2" v-if="bestanswer">其他回答：</h2>
                    <div class="replay-list clearfix" v-for="item in  answers" :key="item.index">
                        <div class="replay01">
                            <div class="replay-top date clearfix">
                                <p class="fl clearfix">
                                    <span>
                                        <img v-bind:src="item.HeadImg" style="width: 25px"> {{item.RealName}}
                                    </span>
                                    <span>{{item.CreateTime|datetime("YYYY-MM-DD HH:mm")}}</span>
                                </p>
                                <p class="fr clearfix redecn">
                                    <span class="re" v-on:click="setvalue(item.AnswerId)">
                                        <i class="replay"></i>回复
                                    </span>

                                    <span class="de" v-if="item.AuthorId==currentuser" v-on:click="deleteanswer(item.AnswerId)">
                                        <i class="delete"></i>删除
                                    </span>

                                    <span class="cn" v-if="!qinfo.BestAnswer&&qinfo.AuthorId==currentuser" v-on:click="adopt(item.AnswerId)">
                                        <i class="caina"></i>采纳
                                    </span>
                                </p>
                            </div>
                            <div class="replay-bottom mb20" v-html="htmlEncode(item.Content)"></div>
                          
                            <div class="clearfix fr txtcon" v-if="item.AnswerId==tempid">
                                <textarea id="textarea" autofocus="autofocus"></textarea>
                                <button class="fa-re mt10 btn btn-clear" v-on:click="replya(item.AnswerId)">发表回复</button>
                            </div>
                        </div>
                         <!-- <div class="replay02" v-if="r.ParentId==item.AnswerId" >
                            <div class="replay-top date clearfix" v-for="r in reply" :key="r.index">
                                <p class="fl clearfix">
                                    <span>
                                        <img v-bind:src="r.HeadImg" style="width: 25px"> {{r.RealName}} 的回复
                                    </span><span>{{r.CreateTime}}</span>
                                </p>
                                <p class="fr clearfix redecn">
                                    <span class="de" v-if="r.AuthorId==currentuser" v-on:click="deleteanswer(r.AnswerId)">
                                        <i class="delete"></i>删除
                                    </span>
                                </p>
                            </div>
                            <div class="replay-bottom mb20" v-html="htmlDecode(r.Content)"></div>
                        </div>  -->
                    </div>

                </div>

                <div class="edit-content mt60">
                    <h2 class="mb10">我的回答：</h2>
                    <div class="f-r ib posr">
                         <ueditor id="editor-demo-01"></ueditor>
                    </div>
                </div>
                <div class="tc mt20">
                    <button class="btn btn-submit" id="answerSubmit" v-on:click="submit">提交</button>
                    <button class="btn btn-clear" v-on:click="closepage">取消</button>
                </div>
            </div>
        </div>
        <div class="fr list-right question-right">
            <h3 class="h3-top">相似问题</h3>
            <label v-if="similar.length==0">暂无数据</label>
            <div class="clear mt10 mb10" v-for="item in similar" :key="item.index">
                <a class="h3 ellipsis question" v-bind:href="'/QuestionDetail?qid='+item.QuestionId" target="_blank">{{htmlDecode(item.Title)}}</a>
                <p class="clearfix date">
                    <span class="fl">{{item.CreateTime}}</span>
                    <span class="fr">{{item.AnswerNum}}回复({{item.CreatTimeTimeShow}})</span>
                </p>
            </div>
        </div>
    </div>
</div>

  </div>
</template>

<script>
import Navigation from "./navigation.vue";
import HeaderQ from "../faq/components/header.vue"
import { GetQuestionInfo,GetAnswersByQId} from '@/api/faq'
import ueditor from'./ueditor.vue'
export default {
  name:'QuestionDetail',
  components: {Navigation,HeaderQ,ueditor},
  props:{},
  data () {
  return {
    qinfo: "",
    bestanswer:"",
    answers: [],
    reply:"",
    similar:[],
    currentuser:'',
    tempid:'',
    qid:this.$route.query.qid,
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted(){
      this.GetQuestionInfo();
      this.GetAnswersByQId()
  },
  methods: {
     async GetQuestionInfo(){
        var data= await GetQuestionInfo({
            qid:this.qid
        })
        this.qinfo=data
        console.log("qinfo",data)
      },
     async GetAnswersByQId(){
        var data= await GetAnswersByQId({
            qid:this.qid
        })
        this.answers=data
       console.log("GetAnswersByQId",data)
      },
      htmlEncode(str){
        if(str!=undefined){
          return str.replaceAll ("&lt;","<").replaceAll ("&gt;",">").replaceAll("&amp;nbsp;","");  
        }                                                                                                    
         //return str.replace(/<\/?.+?\/?>/g,'')
      },
      htmlDecode(){

      },
      setvalue(aid) {
        console.log(aid)
         this.tempid = aid;
        },
      submit(){

      },
      closepage(){

      },
      deleteanswer(){

      },
      focuseEditor(){
         var ue = UE.getEditor('editor-demo-01');
                    ue.focus();
                     var windowHeight;
                    if ((document.body) && (document.body.clientHeight))
                        windowHeight = document.body.clientHeight;
                    else if (window.outerHeight)
                        windowHeight = window.outerHeight;
                    window.scrollTo(0, windowHeight);
      }
  }

}

</script>
<style lang='less'>
</style>